package msr.frontend;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import msr.object.Capacity;
import msr.object.Jichiku;
import msr.object.User;
import msr.service.OracleService;
import msr.service.UserService;
import msr.util.RequestAction;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BookingAction extends ActionSupport {
	/**
	 * 
	 */
	Map<String, Object> session = ActionContext.getContext().getSession();
	private String username;
	private String passwd;
	private OracleService oService = new OracleService();
	private UserService uService = new UserService();
	private List<Capacity> listCapacity;
	private List<Jichiku> listJichiku;
	private static final long serialVersionUID = 1L;
	private String productcode;
	private String productname;
	private String productcapacity;
	private String productgetcd;
	private int seqno;
	private String farmcd;
	private String prefcd;
	private String jikokind;
	private int nokisaki;
	private String formname;
	private String jichikucd;
	private String jichikuname;
	private String actionType;

	public String execute() {
		System.out.println("action " + this.getClass());
		// get list capacity from database
		this.setUsername((String) session.get("username"));
		this.setPasswd((String) session.get("passwd"));
		System.out.println("value of code " + productcode);
		System.out.println("value of seqno " + seqno);
		System.out.println("value of name " + productname);
		System.out.println("value of productcapacity" + productcapacity);
		System.out.println("value of formname " + formname);
		System.out.println("value of jichikucd " + jichikucd);
		System.out.println("value of jichikuname " + jichikuname);
		System.out.println("value of actionType " + actionType);
		if (productcode != null && productcapacity != null)
			listCapacity = oService.getListCapacity(productcapacity);
		if (actionType != null) {
			Map<String, Object> params = new HashMap<String, Object>();
			if (actionType.equals(RequestAction.SEARCH_REGISTER)) {
				params.put("username", (String) session.get("username"));
				listJichiku = oService.getListJichiku(params,
						RequestAction.GET_ALL_JICHIKU_BY_USER);
				User u = uService
						.getLoginUser((String) session.get("username"));
				prefcd = u.getPrefcd();
				farmcd = u.getFarmcd();
			} else if (actionType.equals(RequestAction.HISTORY_REGISTER)) {

				/*
				 * 2 case: 1: get list jichiku by username 2: get list jichiku
				 * by dpln seqno
				 */

				// params.put("seqno", seqno);
				// listJichiku = oService.getListJichiku(params,
				// RequestAction.GET_ALL_JICHIKU_BY_DPLN);
				// System.out.println("size of listjichiku " +
				// listJichiku.size());
				params.put("username", (String) session.get("username"));
				listJichiku = oService.getListJichiku(params,
						RequestAction.GET_ALL_JICHIKU_BY_USER);

			}
		}
		return SUCCESS;
	}

	public String getProductcode() {
		return productcode;
	}

	public void setProductcode(String productcode) {
		this.productcode = productcode;
	}

	public String getProductname() {
		return productname;
	}

	public void setProductname(String productname) {
		this.productname = productname;
	}

	public String getProductcapacity() {
		return productcapacity;
	}

	public void setProductcapacity(String productcapacity) {
		this.productcapacity = productcapacity;
	}

	public List<Capacity> getListCapacity() {
		return listCapacity;
	}

	public void setListCapacity(List<Capacity> listCapacity) {
		this.listCapacity = listCapacity;
	}

	public String getProductgetcd() {
		return productgetcd;
	}

	public void setProductgetcd(String productgetcd) {
		this.productgetcd = productgetcd;
	}

	public int getSeqno() {
		return seqno;
	}

	public void setSeqno(int seqno) {
		this.seqno = seqno;
	}

	public String getFarmcd() {
		return farmcd;
	}

	public void setFarmcd(String farmcd) {
		this.farmcd = farmcd;
	}

	public String getJikokind() {
		return jikokind;
	}

	public void setJikokind(String jikokind) {
		this.jikokind = jikokind;
	}

	public int getNokisaki() {
		return nokisaki;
	}

	public void setNokisaki(int nokisaki) {
		this.nokisaki = nokisaki;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public List<Jichiku> getListJichiku() {
		return listJichiku;
	}

	public void setListJichiku(List<Jichiku> listJichiku) {
		this.listJichiku = listJichiku;
	}

	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

	public String getFormname() {
		return formname;
	}

	public void setFormname(String formname) {
		this.formname = formname;
	}

	public String getJichikucd() {
		return jichikucd;
	}

	public void setJichikucd(String jichikucd) {
		this.jichikucd = jichikucd;
	}

	public String getJichikuname() {
		return jichikuname;
	}

	public void setJichikuname(String jichikuname) {
		this.jichikuname = jichikuname;
	}

	public String getActionType() {
		return actionType;
	}

	public void setActionType(String actionType) {
		this.actionType = actionType;
	}

	public String getPrefcd() {
		return prefcd;
	}

	public void setPrefcd(String prefcd) {
		this.prefcd = prefcd;
	}

}
